package resturant;

import java.io.File;
import java.io.IOException;
import java.util.Scanner;
import java.util.TreeMap;
import java.util.TreeSet;

public class MenuList {
	private TreeSet<MenuItem> Menu;
	
	public MenuList() {
		Menu = new TreeSet<MenuItem> ();
	}
		
	public void process(String filename){

		//read input file and create concordance
		String currentpath = "D:\\F21AS Resturant\\src\\resturant\\";
		readAndCreate(currentpath+ filename);  
	}
	
	private void readAndCreate(String filename) {
		Scanner lineScanner; 
		int lineNum = 1;  // The number of the line in the input

		try {  
			// read and process each line in the input file
			lineScanner = new Scanner(new File(filename));
			while (lineScanner.hasNext()){
				processLine(lineScanner.nextLine());
				lineNum++;  // inc line number
			}
		}
		catch (IOException e) {
			System.out.println("Error: Can't open input file ");
			System.exit(1);
		}
	}
      
	/*
	 * Separate out each word in the line
	 * and add these to the reference     
	 */
	private void processLine(String line) {
		String[] words = line.split(",");
		MenuItem item;
		if(words.length == 3){
			item = new MenuItem(words[0].trim(),Double.parseDouble(words[1].trim()),words[2].trim());
			if (!Menu.contains(item)){
			Menu.add(item);
			}
			else{	
				//TODO: Throw Exception
				}
			}
		else{
			//TODO: Throw Exception
		}
		}	


public TreeSet<MenuItem> GetMenu(){
	
	return Menu;
	}

	}
